import React from 'react'
import { AppRegistry } from 'react-native'

import dva from './utils/dva'
import Router, { routerMiddleware, routerReducer } from './router'
import appModel from './models/app'

const app = dva({
  initialState: {},
  models: [appModel],
  extraReducers: { router: routerReducer },
  onAction: [routerMiddleware],
  onError(e) {
    console.log('onError', e)
  },
  onEffect(effect, { put }, model, actionType) {
    return function*(...args) {
      console.log('loading:true', model)
      yield put({ type: 'app/updateState', payload: { isLoading: true } })
      yield effect(...args)
      console.log('loading:false', model)
      yield put({ type: 'app/updateState', payload: { isLoading: false } })
    }
  },
})

// app.use(createLoading());
const App = app.start(<Router />)

AppRegistry.registerComponent('DvaStarter', () => App)
